<?php
namespace App\Listeners;

use App\Events\In\NormalBuyingFinished;
use App\Models\PhonicsStudent;
use App\Models\User;

class OnNormalBuyingFinished
{
    const PHONICS_TRIAL_PRODUCT_ID = 1036;

    /**
     * 购买拼读体验课，获得分享特权
     * @param NormalBuyingFinished $event
     */
    public function handle(NormalBuyingFinished $event)
    {

    }

    protected function handlePhonicsTrialProduct($event)
    {
        $studentId = intval($event->studentId);
        $productId = intval($event->productId);
        if ($productId !== self::PHONICS_TRIAL_PRODUCT_ID) return;

        $student = PhonicsStudent::createOrFetch($studentId);
        $student->setSharePrivilege(1);
        $student->save();

    }
}